import request from '@/utils/request'
import type { PageDto, PageReqDto, PagesDto } from '../types'
import type { AddOccupationReqDto, EditOccupationReqDto, InsureCompanyOccupationDto, InsureIndustryListDto } from './types'


/**
 * 获取长期保行业列表
 * @param params 
 * @returns 
 */
export function getInsureIndustryList(params: {
    name?: string
}): Promise<InsureIndustryListDto[]> {
    return request.get('/crm-prod-v2/web/pc/crm/insureIndustry/queryList', {
        params
    })
}

/**
 * 新增行业
 * @param data 
 * @returns 
 */
export function addInsureIndustry(data: {
    name: string
}): Promise<void> {
    return request.post('/crm-prod-v2/web/pc/crm/insureIndustry', data)
}

/**
 * 编辑行业
 * @param data 
 * @returns 
 */
export function editInsureIndustry(data: {
    name: string,
    id: number
}): Promise<void> {
    return request.put('/crm-prod-v2/web/pc/crm/insureIndustry', data)
}

/**
 * 新增行业工种
 * @param data 
 * @returns 
 */
export function addOccupation(data: {
    industryId: number
    name: string
    level: number
}): Promise<void> {
    return request.post('/crm-prod-v2/web/pc/crm/insureIndustry/occupation', data)
}

/**
 * 编辑行业工种
 * @param data 
 * @returns 
 */
export function editOccupation(data: {
    id: number
    industryId: number
    name: string
    level: number
}): Promise<void> {
    return request.put('/crm-prod-v2/web/pc/crm/insureIndustry/occupation', data)
}

/**
 * 通过occupationId查询关联的保司工种列表
 * @param occupationId 
 * @returns 
 */
export function queryCompanyOccupationListByOccupationId(occupationId: number): Promise<InsureCompanyOccupationDto[]> {
    return request.get(`/crm-prod-v2/web/pc/crm/insureIndustry/queryCompanyOccupationListByOccupationId/${occupationId}`)
}

/**
 * 新增关联的保司工种
 * @param data 
 * @returns 
 */
export function addCompanyOccupation(data: AddOccupationReqDto): Promise<void> {
    return request.post('/crm-prod-v2/web/pc/crm/insureIndustry/addCompanyOccupation', data)
}

/**
 * 编辑关联的保司工种
 * @param data 
 * @returns 
 */
export function editCompanyOccupation(data: EditOccupationReqDto): Promise<void> {
    return request.put('/crm-prod-v2/web/pc/crm/insureIndustry/editCompanyOccupation', data)
}

/**
 * 删除关联的保司工种
 * @param companyOccupationId 
 * @returns 
 */
export function deleteCompanyOccupation(companyOccupationId: number): Promise<void> {
    return request.delete(`/crm-prod-v2/web/pc/crm/insureIndustry/deleteCompanyOccupation/${companyOccupationId}`)
}

/**
 * 导出工种
 * @param insureCompanyId 
 * @returns 
 */
export function exportOccupation(insureCompanyCode: string): Promise<Blob> {
    return request.get(`/crm-prod-v2/web/pc/crm/insureIndustry/exportOccupation/${insureCompanyCode}`, {
        responseType: 'blob'
    })
}

/**
 * 下载工种导入模板
 * @returns 
 */
export function downloadTemplate(): Promise<Blob> {
    return request.get('/crm-prod-v2/web/pc/crm/insureIndustry/downloadTemplate', {
        responseType: 'blob'
    })
}

/**
 * 导入工种
 * @returns 
 */
export function importOccupation(data: FormData, insureCompanyCode: string): Promise<void> {
    return request.post(`/crm-prod-v2/web/pc/crm/insureIndustry/import?insureCompanyCode=${insureCompanyCode}`, data)
}

